<?php
    /**
     * User: Lee
     * Date: 2017/9/29
     */

    namespace Home\Controller;

    use Think\Controller;
    use Home\Service\BillApiService;
    use Home\Service\UserService;


    class BillApiController extends Controller{
        /**
         * 新增销售订单
         */

        public function addSOBill_api(){
            if( IS_POST ){
                header( "Content-type: application/json" );
                $post = file_get_contents( 'php://input' );
                $post = json_decode( $post, true );
                $params[ 'loginName' ] = $post[ 'loginName' ];
                $params[ 'password' ] = $post[ 'password' ];
                $us = new UserService();
                $loginRe = $us->doLogin( $params );
                if( $loginRe[ 'success' ] == true ){
                    $ps = new BillApiService();
                    $this->ajaxReturn( $ps->addSOBill_api( $post ), 'json' );
                } else{
                    $this->ajaxReturn( $loginRe, 'json' );
                }
            }
        }

        /**
         * 新增销售退货入库单
         */
        public function addWSBill_api(){
            if( IS_POST ){
                header( "Content-type: application/json" );
                $post = file_get_contents( 'php://input' );
                $post = json_decode( $post, true );
                $params[ 'loginName' ] = $post[ 'loginName' ];
                $params[ 'password' ] = $post[ 'password' ];
                $us = new UserService();
                $loginRe = $us->doLogin( $params );
                if( $loginRe[ 'success' ] == true ){
                    $ws = new BillApiService();
                    $this->ajaxReturn( $ws->addWSBill_api( $post ), 'json' );
                } else{
                    $this->ajaxReturn( $loginRe, 'json' );
                }
            }
        }

        /**
         * 新增销售退货入库单
         */
        public function addITBill_api(){
            if( IS_POST ){
                header( "Content-type: application/json" );
                $post = file_get_contents( 'php://input' );
                $post = json_decode( $post, true );
                $params[ 'loginName' ] = $post[ 'loginName' ];
                $params[ 'password' ] = $post[ 'password' ];
                $us = new UserService();
                $loginRe = $us->doLogin( $params );
                if( $loginRe[ 'success' ] == true ){
                    $is = new BillApiService();

                    $this->ajaxReturn( $is->addITBill_api( $post ) );
                } else{
                    $this->ajaxReturn( $loginRe, 'json' );
                }
            }
        }
    }